package com.ruoyi.Warehouse.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.Warehouse.domain.Inventoryalerts;
import com.ruoyi.Warehouse.service.IInventoryalertsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 库存预警设置表Controller
 * 
 * @author ruoyi
 * @date 2025-06-16
 */
@Controller
@RequestMapping("/pims/inventoryalerts")
public class InventoryalertsController extends BaseController
{
    private String prefix = "pims/inventoryalerts";

    @Autowired
    private IInventoryalertsService inventoryalertsService;

    @RequiresPermissions("pims:inventoryalerts:view")
    @GetMapping()
    public String inventoryalerts()
    {
        return prefix + "/inventoryalerts";
    }

    /**
     * 查询库存预警设置表列表
     */
    @RequiresPermissions("pims:inventoryalerts:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Inventoryalerts inventoryalerts)
    {
        startPage();
        List<Inventoryalerts> list = inventoryalertsService.selectInventoryalertsList(inventoryalerts);
        return getDataTable(list);
    }

    /**
     * 导出库存预警设置表列表
     */
    @RequiresPermissions("pims:inventoryalerts:export")
    @Log(title = "库存预警设置表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Inventoryalerts inventoryalerts)
    {
        List<Inventoryalerts> list = inventoryalertsService.selectInventoryalertsList(inventoryalerts);
        ExcelUtil<Inventoryalerts> util = new ExcelUtil<Inventoryalerts>(Inventoryalerts.class);
        return util.exportExcel(list, "库存预警设置表数据");
    }

    /**
     * 新增库存预警设置表
     */
    @RequiresPermissions("pims:inventoryalerts:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存库存预警设置表
     */
    @RequiresPermissions("pims:inventoryalerts:add")
    @Log(title = "库存预警设置表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Inventoryalerts inventoryalerts)
    {
        return toAjax(inventoryalertsService.insertInventoryalerts(inventoryalerts));
    }

    /**
     * 修改库存预警设置表
     */
    @RequiresPermissions("pims:inventoryalerts:edit")
    @GetMapping("/edit/{alertId}")
    public String edit(@PathVariable("alertId") Long alertId, ModelMap mmap)
    {
        Inventoryalerts inventoryalerts = inventoryalertsService.selectInventoryalertsByAlertId(alertId);
        mmap.put("inventoryalerts", inventoryalerts);
        return prefix + "/edit";
    }

    /**
     * 修改保存库存预警设置表
     */
    @RequiresPermissions("pims:inventoryalerts:edit")
    @Log(title = "库存预警设置表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Inventoryalerts inventoryalerts)
    {
        return toAjax(inventoryalertsService.updateInventoryalerts(inventoryalerts));
    }

    /**
     * 删除库存预警设置表
     */
    @RequiresPermissions("pims:inventoryalerts:remove")
    @Log(title = "库存预警设置表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(inventoryalertsService.deleteInventoryalertsByAlertIds(ids));
    }
}
